package com.xssn.fjnd.user.controller;


import com.baomidou.mybatisplus.annotation.TableField;
import com.xssn.fjnd.entities.Member;
import com.xssn.fjnd.entities.Photo;
import com.xssn.fjnd.user.req.MemberREQ;
import com.xssn.fjnd.user.service.IMemberService;
import com.xssn.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 成员信息表 前端控制器
 * </p>
 *
 * @author 线狮少年
 * @since 2023-08-16
 */
@Api(value = "线狮成员管理接口", description = "线狮成员管理接口，提供成员的增删改查")
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private IMemberService memberService;


    @PreAuthorize("hasAuthority('member:search')")
    @ApiOperation("根据成员昵称和职位分页列表接口")
    @PostMapping("/search") // localhost:8001/content/photo/search
    public Result search(@RequestBody MemberREQ req) {
        return memberService.queryPage(req);
    }



    @ApiOperation("查询线狮成员详情接口")
    @ApiImplicitParam(name = "id", value = "成员ID", required = true)
    @GetMapping("/{id}")
    public Result view(@PathVariable String id) {

        return memberService.getMemberById(id);
    }

    @PreAuthorize("hasAuthority('member:edit')")
    @ApiOperation("修改线狮成员信息接口")
    @PutMapping
    public Result update(@RequestBody Member member) {
        return memberService.updateOrSave(member);
    }


    @PreAuthorize("hasAuthority('member:add')")
    @ApiOperation("新增线狮成员信息接口")
    @PostMapping
    public Result save(@RequestBody Member member) {
        return memberService.updateOrSave(member);
    }

    @PreAuthorize("hasAuthority('member:delete')")
    @ApiImplicitParam(name = "id", value = "线狮成员ID", required = true)
    @ApiOperation("删除线狮成员接口")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id) {

        return memberService.deleteById(id);
    }


}
